package a_File1;

import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;

public class FileTest3 {
    @Test
    public void test1(){
        File file = new File("src/a_File/b.txt");
        boolean exists = file.exists();
        System.out.println(exists);
    }

    @Test
    public void test2() throws IOException {


        File a = new File("a/b");
        boolean mkdir = a.mkdirs();

        File b = new File("c/b/a");
        boolean mkdir1 = b.mkdirs();

        File file = new File("a/b/aa.txt");
        file.createNewFile();

        File delete_a = new File("a/b");
        boolean delete = delete_a.delete();
        System.out.println(delete);
    }
    @Test
    public void test3(){
        File file = new File("c");
        String[] list = file.list();
        for (String s: list) {
            System.out.println(s);
        }

        System.out.println("------------------");

        File[] files = file.listFiles();
        for (File s: files) {
            System.out.println(s);
        }

        System.out.println("------------------");
    }

    @Test
    public void test4() {
        File file = new File("a");
        deleteFile(file);

    }

    public void deleteFile(File file){
        //获取file中的所有目录/文件
        File[] files = file.listFiles();
        if(files != null){
            for(File f: files){
                deleteFile(f);
            }
        }
        file.delete();
    }
}
